package com.kmxd.ams.core.common.enums;

import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 审批操作
 *
 * @author zuolg
 */
@Getter
@AllArgsConstructor
public enum FlowAuditEnum {
  /** 审核 */
  AGREE("agree", "审核", "blue"),
  /** 同意并完成 */
  AGREED_COMPLETE("agreedComplete", "同意并结束", "green"),
  /** 作废 */
  INVALID("invalid", "作废", "red"),
  /** 退回 */
  RETURN_TO("returnTo", "退回", "red"),
  /** 退回撰写人 */
  RETURN_AUTHOR("returnToAuthor", "退回撰写人", "red"),
  /** 撤回--特殊处理 */
  REVOKE("revoke", "撤回", "red"),
  /** 改派 */
  TO_SEND("toSend", "改派", "blue"),
  /** 协助 */
  TO_ASSIST("toAssist", "协助", "blue"),
  /** 提交 */
  SUBMIT("submit", "提交", "blue"),
  /** 结束 */
  END("end", "结束", "green"),
  /** 待处理 */
  WAITING("waiting", "待处理", "blue"),

  /** 处理完成 */
  COMPLETE("completed", "处理完成", "green");

  private String code;
  private String desc;
  private String color;

  public static FlowAuditEnum convert(String type) {
    return Arrays.stream(values())
        .filter(x -> x.code.equals(type))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到此操作定义！：" + type));
  }
}
